package org.trade.web.simple;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * 可靠的同步发送：消息发送方发出后，会在收到对方响应之后才发下一个数据包
 * 此种场景应用广泛，例如重要的通知邮件，报名短信通知，营销短信系统
 */
public class SyncProducer {

	public static void main(String[] args) {
		DefaultMQProducer producer = new DefaultMQProducer("fang_group_name");
		producer.setNamesrvAddr("106.14.154.169:9876");
		try {
			producer.start();
			for (int i = 0; i < 100; i++) {
				// Topic,Tag,Message body
				Message msg = new Message("TopicTest", "TagA",
						("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));

				SendResult sendResult = producer.send(msg);
				System.out.printf("%s%n", sendResult);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		producer.shutdown();
	}
}